package com.rockbb.common.simpleframe.result;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class StreamProcessor {

	private static Logger logger = Logger.getLogger(RawProcessor.class);

	public static void process(HttpServletResponse res, String type, String disposition, String filename, Object streamBytes) 
	{
		try 
		{
			res.setHeader("Cache-Control", "no-store");
			res.setHeader("Pragma", "no-cache");
			if (disposition != null && disposition.length()>0)
				res.setHeader("Content-Disposition", disposition+"; filename=\""+filename+"\"");
			res.setDateHeader("Expires", 0);
			res.setContentType(type);
			ServletOutputStream responseOutputStream = res.getOutputStream();
			responseOutputStream.write((byte[])streamBytes);
			responseOutputStream.flush();
			responseOutputStream.close();
		} 
		catch (Exception e) 
		{
			logger.info("Unknown Exception");
			logger.debug("Exception details:", e);
		}
	}
}
